// const Express = require('express')  Commonjs
import Express from 'express'
import { UserRouter } from './router/user.js';
import { captchaRouter } from './router/captcha.js';
import cookieParser from 'cookie-parser';
import Session from 'express-session';
import './DB/initDB.js'
import { errorMiddleware } from './middleware/errerMiddleware.js';
import { UploadRouter } from './router/upload.js';
import { typeRouter } from './router/type.js';
import { articleRouter } from './router/article.js';
import { commentRouter } from './router/comment.js';
const server = Express();

server.use(Express.json());
server.use(cookieParser())
server.use(Express.static('./static/avatar'))
server.use(Express.static('./static/upload'))
server.use(Session({
    secret:'buka',
    saveUninitialized: true,
    resave: true
}))
// 完成路由封装
server.use("/api/user", UserRouter)
server.use("/api/captcha", captchaRouter)
server.use('/api/upload', UploadRouter)
server.use('/api/type',typeRouter)
server.use('/api/issue', articleRouter)
server.use('/api/comment', commentRouter)

server.use(errorMiddleware)

server.listen(8090,()=>{
    console.log("服务器运行在8090端口");
})